package com.team.game.Game;

import android.graphics.Canvas;
import android.graphics.PathMeasure;
import android.graphics.PointF;
import android.graphics.RectF;

import com.team.game.Game.Boses.Boss1;
import com.team.game.framework.Abstract.Boses;
import com.team.game.framework.Abstract.Waves;
import com.team.game.framework.impl.SurfaceThread;

public class Boss_Wave implements Waves {

    private float Time;
    private int Num_Mini_Wave;
    private boolean[] Wave_Reboot;
    private float[] Time_Wave_Reboot;
    private int Num_Mob_Reboot_Start[];
    private float Num_Mob_Reboot_End[];
    private Wave Boss_Wave;
    private Boses Boss;

    public Boss_Wave(int type_Boss, PathMeasure[] pathMeasure) {
        if (type_Boss == 1) {
            Boss = new Boss1(pathMeasure);
            Num_Mini_Wave = 2;
            Wave_Reboot = new boolean[]{false, false};
            Num_Mob_Reboot_Start = new int[]{0, 3};
            Num_Mob_Reboot_End = new float[]{2, 5};
            Time_Wave_Reboot = new float[]{12, 24};
            Boss_Wave = new Wave(6, new int[]{1, 1, 1, 0, 0, 0}, new float[]{0.5f, 0.5f, 0.5f, 10.8f, 10.8f, 10.8f}, new int[]{0, 1, 2, 0, 1, 2}, pathMeasure);
        }
    }

    @Override
    public void WaveDraw(Canvas canvas) {
        Boss.drawSprite(canvas);
        Boss_Wave.WaveDraw(canvas);
    }

    @Override
    public void WaveUpdate() {
        Time += SurfaceThread.deltaTime;
        for (int i = 0; i < Num_Mini_Wave; i++) {
            if (!Wave_Reboot[i]) {
                if (Time_Wave_Reboot[i] <= Time) {
                    if (!Boss.deadSearch) {
                        for (int j = Num_Mob_Reboot_Start[i]; j < Num_Mob_Reboot_End[i] + 1; j++) {
                            Boss_Wave.Mob_Reboot(j, false);
                            Wave_Reboot[i] = true;
                        }
                        if (Num_Mini_Wave - 1 == i) {
                            Time = 0;
                            for (int l = 0; l < Num_Mini_Wave; l++) {
                                Wave_Reboot[l] = false;
                            }
                            continue;
                        }
                    }
                } else
                    continue;
            }
        }
        Boss.updateSprite();
        Boss_Wave.WaveUpdate();
    }

    PointF BossWavePointF = new PointF();
    PointF BossPointF = new PointF();
    @Override
    public PointF WaveSearchMob(float x, float y, float init, float radius1) {
        BossPointF = Boss.getAllPosition(x, y, init, radius1);
        BossWavePointF = Boss_Wave.WaveSearchMob(x, y, init, radius1);

        if (BossWavePointF.x == -1 && BossPointF.x == -1)
            return BossWavePointF;
        else {
            if (BossWavePointF.y < BossPointF.y)
                return BossWavePointF;
            else
                return BossPointF;
        }
    }

    @Override
    public void WaveDispose() {
        Boss_Wave.WaveDispose();
    }


    @Override
    public RectF waveGetPosition(int mob) {
        if (mob >= 100)
            return Boss.getRect(mob);
        else
            return Boss_Wave.waveGetPosition(mob);
    }

    @Override
    public void mobStrike(int mob, float kick) {
        if (mob >= 100)
            Boss.dec(mob, kick);
        else
            Boss_Wave.mobStrike(mob, kick);
    }

    @Override
    public void WaveRestart() {
        Boss.restart();
        Boss_Wave.WaveRestart();
    }

//    @Override
//    public void impactOnDegRect (RectF rectF, float alpha, PointF pnt, float damage) {
//        Boss_Wave.impactOnDegRect (rectF, alpha, pnt, damage);
//    }
//    @Override
//    public void impactOnTheRadius(PointF pointF, float Damage, float Radius) {
//        Boss_Wave.impactOnTheRadius(pointF, Damage, Radius);
//    }
}